package com.springapp.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by tandan on 16-10-12.
 */
public class DataParser {

    public static void main(String[] args) {
        /*String a = "root/emc:Symm_RaidGroup.CreationClassName=\"Symm_RaidGroup\",DeviceID=\"SYMMETRIX+000295900194+3;2;;;;;;0;0018A;\",SystemCreationClassName=\"Symm_StorageSystem\",SystemName=\"SYMMETRIX+000295900194\"";
        String[] array = a.split(",");
        Map map = new HashMap();
        for(int i=0;i<array.length;i++){
            String mapKey = array[i].substring(0,array[i].indexOf("=")).replaceAll("\"","");
            String mapValue = array[i].substring(array[i].indexOf("=")+1).replaceAll("\"", "");
            System.out.println(mapKey + "----" + mapValue);
            map.put(mapKey,mapValue);
        }*/

    }




    /**
     *
     * @param str Symm_DeviceStoragePool.InstanceID="SYMMETRIX+000295900194+C+0001"
     * @return SYMMETRIX+000295900194+C+0001
     */
    public static String Symm_DeviceStoragePool_GroupComponent(String str){
        Map _map = parsMapObj(str);
        return (String)_map.get("root/emc:Symm_DeviceStoragePool.InstanceID");
    }

    /**
     *
     * @param str root/emc:Symm_RaidGroup.CreationClassName=\"Symm_RaidGroup\",DeviceID=\"SYMMETRIX+000295900194+3;2;;;;;;0;0018A;\",SystemCreationClassName=\"Symm_StorageSystem\",SystemName=\"SYMMETRIX+000295900194\"
     * @return SYMMETRIX+000295900194
     */
    public static String Symm_DeviceStoragePool_PartComponent(String str){
        Map _map = parsMapObj(str);
        return (String)_map.get("SystemName");
    }



    /**
     * 指定格式string解析为map对象
     * @param str
     *      root/emc:Symm_RaidGroup.CreationClassName=\"Symm_RaidGroup\",DeviceID=\"SYMMETRIX+000295900194+3;2;;;;;;0;0018A;\",SystemCreationClassName=\"Symm_StorageSystem\",SystemName=\"SYMMETRIX+000295900194\"
     * @return _map
     *      root/emc:Symm_RaidGroup.CreationClassName----Symm_RaidGroup
            DeviceID----SYMMETRIX+000295900194+3;2;;;;;;0;0018A;
            SystemCreationClassName----Symm_StorageSystem
            SystemName----SYMMETRIX+000295900194
     */
    public static Map parsMapObj(String str){
        Map _map = new HashMap();
        String[] array = str.split(",");
        for(int i=0;i<array.length;i++){
            String mapKey = array[i].substring(0,array[i].indexOf("=")).replaceAll("\"","");
            String mapValue = array[i].substring(array[i].indexOf("=")+1).replaceAll("\"", "");
            //System.out.println(mapKey + "----" + mapValue);
            _map.put(mapKey,mapValue);
        }
        return _map;
    }



}
